package org.wh1tew0lf.vframe.framework.vframeexception;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.json.JSONObject;

@SuppressWarnings("serial")
public abstract class VFrameException extends Throwable {

	private static SimpleDateFormat sdf = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss.SSS");

	protected Date createdDateTime;
	protected String className;
	protected String fileName;
	protected String methodName;
	protected int lineNumber;

	public VFrameException() {
		this.createdDateTime = new Date();
		StackTraceElement ste = (new Throwable()).getStackTrace()[1];
		this.className = (ste == null) ? "<null>" : ste.getClassName();
		this.fileName = (ste == null) ? "<null>" : ste.getFileName();
		this.methodName = (ste == null) ? "<null>" : ste.getMethodName();
		this.lineNumber = (ste == null) ? -1 : ste.getLineNumber();
	}

	protected String getLogPrefix() {
		return "Class " + this.className + " has thrown an Exception @ "
				+ VFrameException.sdf.format(createdDateTime) + " in method "
				+ this.methodName + " , in file " + this.fileName + " at line "
				+ this.lineNumber + ".";
	}

	public abstract String getLogString();

	public abstract String getJSString();

	public abstract JSONObject getJSONObject();
}
